package com.fanjia.crm.web.controller;

import com.fanjia.crm.model.CURDResult;
import com.fanjia.crm.model.CourseOrder;
import com.fanjia.crm.model.PageResult;
import com.fanjia.crm.model.Permission;
import com.fanjia.crm.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by FanJia on 2020/9/21 14:40
 */
@Controller
@RequestMapping(value = "/permission")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;


    @RequestMapping("/list")
    public String list(){
        return "/permission/list";
    }

    @RequestMapping("/add")
    public String add(Model model){
        List<Permission> parentMenus = permissionService.findAllParentMenus();
        model.addAttribute("parentMenus",parentMenus);
        return "/permission/add";
    }



    @RequestMapping("/save")
    @ResponseBody
    public CURDResult save(Permission permission){
        CURDResult result = new CURDResult();
        System.out.println(permission);
        permissionService.insert(permission);
        return result;
    }


    @RequestMapping("/listjson")
    @ResponseBody
    public PageResult<Permission> listJson(CourseOrder condition){
        System.out.println(condition);
        PageResult<Permission> result = new PageResult<>();
        result.setData(permissionService.findAllPermission());
        return result;

    }




}
